<?php
/**
 * User: Hunman
 * Date: 17.07.13
 * Time: 21:44
 */
class Model_Product extends Model_Default
{

    function __construct()
    {
//        $this->getContent();
    }

    /**
     * Пример
     */

    function getProductData($id)
    {
        $id = (int) $id;
        $sql = <<<SQL
                   SELECT
                      t.id, t.Name, t.Image, t.Price, t.PriceOld, t.Data, t.mini_data, t.color,
                      tc.podcat AS podcat_id, tc.cat AS cat_id, pd.podcat AS podcat_name, cd.cat AS cat_name
                   FROM
                      Tovar AS t
                   LEFT JOIN
                      Tovar_cat AS tc ON tc.id_tovar = t.id
                   RIGHT JOIN
                      podcat_data AS pd ON pd.id = tc.podcat
                   RIGHT JOIN
                      cat_data AS cd ON cd.id = tc.cat
                   WHERE
					  t.id =  $id
				   AND
					  t.in_moderate = 0
				   AND
					  t.is_hide = 0

SQL;
		//чтение кеша
		$result = $this->cache($sql);
		if ($result == null)
		{
			$db = $this->dbh();
			$stmt = $db->query($sql);
			$result = $stmt->fetch(PDO::FETCH_ASSOC);
			//запись в кеш
			$this->cache($sql, $result);
		}
        return $result;
    }
}
